


        //动画延迟
        var beginningDelay = null;
        var animateDelayCount = 500;
        //计时
        var timeRecording = null;
        var letterWaveDelayBasic = 60;



        var originalWindowWidth = window.innerWidth;
        var bigWidth = originalWindowWidth >= 768?true:false;
        var menuAppearDelay = null;
        var mouseX,mouseY;
        //链接延迟跳转
        var linkJumpCount = 4;
        var linkHref;

        function print(a){
            console.log(a);
        }
        //判断是否为移动设备
        function browserRedirect(){
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
            if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
                $('body').addClass('mobileDevice');
            }
        }
        function splitLetter(box,txt){
            for(var l = 0;l < txt.length;l++){
                var span = document.createElement('span');
                span.style.animationIterationCount = 'infinite';
                span.innerHTML = txt[l];
                box.appendChild(span);
            }
        }
        function countDown(){
            linkJumpCount -= 1;
            //linkJumpCount=0时，跳转页面
            if(linkJumpCount <= 0){
                location.href = linkHref;
            }
            //每秒执行一次,showTime()
            setTimeout("countDown()",500);
        }
        function getBg(val){

            switch(val){
                case 'about':
                    return '#393';
                case 'saleLocation':
                    return '#333081';
                case 'news':
                    return '#fff';
                default:
                    return '#fb0';
            }
           //return 
        }
        $(document).ready(function(){
            browserRedirect();
            for(var s = 0;s < $('header .letterWaveBox').length;s++){
                $('header .letterWaveBox')[s].oldCal = $('header .letterWaveBox')[s].newCal = 0;
                $('header .letterWaveBox')[s].timeLeft = 0;
                $('header .letterWaveBox')[s].last = $('header .letterWaveBox')[s].children.length;
                $('header .letterWaveBox')[s].timeRecording = null;
                $('header .letterWaveBox')[s].singleCompleteWaving = null;
                $('header .letterWaveBox')[s].leftTimeRecord = 0;
                var innerText = $('header .letterWaveBox:eq(' + s + ')').text();
                $('header .letterWaveBox:eq(' + s + ')').html('');
                splitLetter($('header .letterWaveBox:eq(' + s + ')')[0],innerText);
            }
            $('header .letterWaveBox').mouseenter(function(){
                if($('.mobileDevice ').length) return false;
                $(this).addClass('hover');
                var This = $(this);
                This[0].oldCal = This[0].newCal;
                
                clearInterval($(this)[0].singleCompleteWaving);
                //需加上次遗留的倒计时才是前后鼠标停留在漂浮文字上的实际时间
                This[0].newCal = 0;
                This[0].oldCal += This[0].leftTimeRecord;
                This[0].last = This[0].children.length;
                This[0].leftTimeRecord = 0;
                for(var n = 0;n < This[0].children.length;n++){
                    This[0].children[n].style.animationIterationCount = 'infinite';
                }
                $(this)[0].timeRecording = setInterval(function(){
                    This[0].newCal = This[0].newCal + 10;
                },10)
            })
            $('header .letterWaveBox').mouseleave(function(){
                if($('.mobileDevice ').length) return false;
                clearInterval($(this)[0].timeRecording);
                var This = $(this);
                
                var timesBasic = parseInt((This[0].oldCal + This[0].newCal - letterWaveDelayBasic) / 1000);
                console.log(This[0].newCal + This[0].oldCal);
                for(var c = 0;c < This[0].children.length;c++){
                    if(timesBasic * 1000 + (c + 1) * letterWaveDelayBasic >= (This[0].newCal + This[0].oldCal)){
                        This[0].last = c;
                        break;
                    }
                }
                console.log(This[0].last);
                This[0].timeLeft = (letterWaveDelayBasic * This[0].last + (timesBasic + 1) * 1000) - This[0].newCal - This[0].oldCal;
                console.log(This[0].timeLeft);
                
                
                $(this)[0].singleCompleteWaving = setInterval(function(){ 
                    if(This[0].leftTimeRecord > This[0].timeLeft){
                        This.removeClass('hover');
                        This[0].newCal = This[0].oldCal = 0;
                        This[0].last = This[0].children.length;
                        This[0].leftTimeRecord = 0;
                        clearInterval(This[0].singleCompleteWaving);
                    }
                    This[0].leftTimeRecord = This[0].leftTimeRecord + 10;
                        for(var s = 1;s <= This[0].children.length;s++){
                            if(s <= This[0].last){
                                if(This[0].leftTimeRecord > (letterWaveDelayBasic * s + (timesBasic + 1) * 1000) - This[0].newCal - This[0].oldCal){
                                    This[0].children[s - 1].style.animationIterationCount != '0' && (console.log(s,This[0].leftTimeRecord));
                                    This[0].children[s - 1].style.animationIterationCount = '0';
                                }
                            }else if(This[0].oldCal + This[0].newCal > 1000 + letterWaveDelayBasic && s > This[0].last){
                                if(This[0].leftTimeRecord >= (letterWaveDelayBasic * s + timesBasic * 1000) - This[0].newCal - This[0].oldCal){
                                    This[0].children[s - 1].style.animationIterationCount = '0';
                                }
                            }
                            
                        }
                },10)
            })
            
            $('.shave').css('opacity','0');
            mouseX = event.clientX || 0;
            mouseY = event.clientY || 0;
            watchWindow = setInterval(function(){
                if(originalWindowWidth != window.innerWidth){
                    if(bigWidth && window.innerWidth < 768){
                        $('.news').addClass('smallScreen');
                    }
                }
            },10)
            $('.menuBtn').click(function(){
                clearTimeout(menuAppearDelay);
                menuAppearDelay = null;
                if($(this).parent()[0].className.indexOf('active') >= 0){
                    $(this).siblings('ul').removeClass('enter');
                    $('html')[0].style.cssText = '';
                    $(this).parent().removeClass('active');
                    $(this).siblings('ul').addClass('leave');
                    var This = $(this);
                    setTimeout(function(){
                        This.siblings('ul').addClass('enter-to');
                    },10);
                   menuAppearDelay = setTimeout(function(){
                        This.parent().removeClass('enter');
                        This.siblings('ul')[0].style.display = 'none';
                        This.siblings('ul').removeClass('leave');
                        This.siblings('ul').removeClass('enter-to');
                        clearTimeout(menuAppearDelay);
                        menuAppearDelay = null;
                    },510);
                }else{
                    //ios需在html上设置fixed，方可overflow-y：hidden
                    $('html').css({'overflow-y':'hidden','position':'fixed'});
                    $(this).parent().addClass('active');
                    $(this).parent().addClass('enter');
                    $(this).siblings('ul')[0].style.cssText = '';
                    $(this).siblings('ul').removeClass('leave');
                    $(this).siblings('ul').removeClass('enter-to');
                    $(this).siblings('ul').addClass('enter-to');
                    var This = $(this);
                    setTimeout(function(){
                        This.siblings('ul').addClass('enter');
                        This.siblings('ul').removeClass('enter-to');
                    },10)
                   menuAppearDelay = setTimeout(function(){
                        This.siblings('ul').removeClass('enter');
                        clearTimeout(menuAppearDelay);
                        menuAppearDelay = null;
                    },875);
                }
            })

            $('header .menu li a').click(function(){
                $('.menuBtn')[0].click();
            })
            

            $('a').click(function(e){
                    document.documentElement.scrollTop = document.body.scrollTop = 0;
                    linkHref = $(this).attr('href');
                    e = e || window.event;
                    if(e.preventDefault){ // w3c
                        var newBg = getBg(linkHref.split('.html')[0]);
                        $('.shave').css('background',newBg);
                        $('.shave').css('opacity','1');
                        countDown();
                        e.preventDefault();
                    }else { // ie
                        e.returnValue = false;
                    }
            })
        })
        